//#define DEBUG

#include <JsonParser.h>

using namespace ArduinoJson::Parser;

struct jsonVals
{
	String func;	//SET, GET, ACK
	String var;		//PHT, PB1, PB2, TPS, SSID, PW, SEC, BT, SERV, MEM
	String value;	//CONNECT, 
};

//bool msgBT = false;

struct jsonVals parseMsg(char msg[])
{
	struct jsonVals JsonVals;
	JsonParser<9> parser;
	JsonObject root = parser.parse(msg);

	if (!root.success())
	{
		Serial.println(F("Parse failed"));
	}
	else
	{
		JsonObject PKGMsg = root["PKG"];
		JsonVals.func = PKGMsg["FUNC"];
		JsonVals.var = PKGMsg["VAR"];
		JsonVals.value = PKGMsg["VAL"];

#ifdef DEBUG
		Serial.println(JsonVals.var + "\t" + JsonVals.value);
#endif

		return JsonVals;
	}
}

/* Test strings
BT
	{"PKG":{"FUNC":"SET","VAR":"BT","VAL":""}}
Server
	{"PKG":{"FUNC":"SET","VAR":"SERV","VAL":"CONNECT"}}
	{"PKG":{"FUNC":"GET","VAR":"TPS","VAL":""}}

Memory
	{"PKG":{"FUNC":"SET","VAR":"MEM","VAL":"CLR"}}
	
*/
